import 'antd-mobile/dist/antd-mobile.css';
import React, { useState,useEffect } from 'react';
import { getWxCode } from './util/wxService'
import Login from './pages/login'
import Main from './pages/main'

const App = (props) => {
  const [vistible, setVistible] = useState(true);
  console.log(props.match);

  useEffect(() => {
    getWxCode(() => {
      if (localStorage.getItem("WxUserInfo") != null && localStorage.getItem("WxUserInfo") != undefined) {
        const wxInfo = JSON.parse(localStorage.getItem("WxUserInfo"));
        console.log('本存储');
        console.log(wxInfo);
        if (wxInfo != undefined) {
          // 判断是否需要登录
          if (wxInfo.companyId) {
            setVistible(true);
          }else{
            setVistible(false)
          }
        } else {
          return (
            <div>请联系管理员</div>
          )
        }
      } else {
        console.log('没有本地存储');
      }
    })
  },[])
  return (
    vistible ? <Main/> : <Login onClickok={()=>{
      setVistible(true);
    }}/>
  )
}

export default App;